import {
  DIC
} from '@/const/dic'
import {
  checkPhone
} from "@/util/validate.js";

export const option = {
  index: true,
  indexLabel: '序号',
  border: true,
  selection: true,
  menuBtn: true,
  addBtn: false,
  cellBtn: false,
  editBtn: false,
  delBtn: false,
  columnBtn: false,
  refreshBtn: false,
  searchBtn: false,
  size: 'mini',
  dicData: DIC,
  align: "center",
  menuWidth: 220,
  menuAlign: "center",
  column: [{
    label: "设备状态",
    prop: "isRun",
    width: "90",
    // search: true,
    slot: true
  }, {
    label: "借用/预约",
    prop: "options",
    width: "90",
    // search: true,
    slot: true
  }, {
    label: "维保",
    prop: "isMaintain",
    width: "50",
    slot: true
  }, {
    label: "监控",
    prop: "isMonitor",
      width: "50",
    // search: true,
    slot: true
  }, {
    label: "设备类别",
    prop: "name",
    width: "100",
    // search: true,
  }, {
    label: "设备编码",
    prop: "coded",
    width: "100",
  },{
    label: "设备Id",
    prop: "deviceId",
  }, {
    label: "设备名称",
    prop: "name",
  }, {
    label: "型号",
    prop: "marking",
    width: "100",
  }, {
    label: "品牌",
    prop: "brand",
    width: "100",
  }, {
    label: "存放位置",
    prop: "location",
    width: "100",
    // search: true,
    slot: true
  }, {
    label: "保养/效准/预警(天)",
    prop: "maintainCycle",
    width: "140",
    slot: true
    /*    },{
            label: "效准(天)",
            prop: "last_correct_date",
            width: "80",
        },{
            label: "预警(天)",
            prop: "maintain_waring",
            width: "80",*/
  }, {
    label: "最近修改人",
    prop: "updateName",
    width: "100",
  }, {
    label: "时间",
    prop: "alterTime",
      width: "140",
  } ]
};

export const optionAdd = {
  index: true,
  indexLabel: '序号',
  border: true,
  selection: true,
  menuBtn: true,
  addBtn: false,
  cellBtn: false,
  editBtn: false,
  delBtn: false,
    size: 'mini',
  dicData: DIC,
  align: "center",
  menuWidth: 110,
  menuAlign: "center",
  columnBtn: false,
  refreshBtn: false,
  column: [{
    label: "审批单号",
    prop: "name",
    width: "110",
  }, {
    label: "审批状态",
    prop: "name",
    width: "110",
  }, {
    label: "预约时间",
    prop: "name",
    width: "110",
  }, {
    label: "设备类别",
    prop: "name",
    width: "110",
  }, {
    label: "设备编码",
    prop: "sbno",
    width: "110",
  }, {
    label: "设备Id",
    prop: "sbI",
    width: "110",
  }, {
    label: "设备名称",
    prop: "sbname",
    width: "110",
  }, {
    label: "型号",
    prop: "sbxh",
    width: "110",
  }, {
    label: "品牌",
    prop: "品牌",
    width: "110",
  }, {
    label: "实验室",
    prop: "实验室",
    width: "110",
  }, {
    label: "预约部门/人",
    prop: "预约部门",
    width: "110",
  }, {
    label: "申请时间",
    prop: "date",
    width: "110",
  }]
};

export const optionSelect = {
  index: true,
  indexLabel: '序号',
  border: true,
  selection: true,
  addBtn: false,
  cellBtn: false,
    size: 'mini',
  editBtn: false,
  delBtn: false,
  searchBtn: false,
  dicData: DIC,
  align: "center",
  menu: false,
  menuWidth: 110,
  menuAlign: "center",
  columnBtn: false,
  refreshBtn: false,
  column: [{
    label: "审批单号",
    prop: "name",
    width: "110",
  }, {
    label: "审批状态",
    prop: "name",
    width: "110",
  }, {
    label: "预约时间",
    prop: "name",
    width: "110",
  }, {
    label: "设备类别",
    prop: "name",
    width: "110",
    search: true,
  }, {
    label: "设备编码",
    prop: "sbno",
    width: "110",
    search: true,
  }, {
    label: "设备名称",
    prop: "sbname",
    width: "110",
    search: true,
  }, {
    label: "型号",
    prop: "sbxh",
    width: "110",
    search: true,
  }, {
    label: "品牌",
    prop: "品牌",
    width: "110",
  }, {
    label: "实验室",
    prop: "实验室",
    width: "110",
    search: true,
  }, {
    label: "预约部门/人",
    prop: "预约部门",
    width: "110",
  }, {
    label: "申请时间",
    prop: "date",
    width: "110",
  }]
};

// 设备输入规则
export const sbRules = {
  /* string */
  coded: [{
      required: true,
      message: '请输入设备编码',
      trigger: 'blur'
    },
    {
      max: 50,
      message: '输入的长度请在 50 个字符',
      trigger: 'blur'
    }
  ],
  name: [{
      required: true,
      message: '请输入设备名称',
      trigger: 'blur'
    },
    {
      max: 50,
      message: '输入的长度请在 50 个字符',
      trigger: 'blur'
    }
  ],
  marking: [{
      required: true,
      message: '请输入设备型号',
      trigger: 'blur'
    },
    {
      max: 50,
      message: '输入的长度请在 50 个字符',
      trigger: 'blur'
    }
  ],
  brand: [{
      required: true,
      message: '请输入设备品牌',
      trigger: 'blur'
    },
    {
      max: 50,
      message: '输入的长度请在 50 个字符',
      trigger: 'blur'
    }
  ],
  supplier: [{
      required: true,
      message: '请输入供应商',
      trigger: 'blur'
    },
    {
      max: 50,
      message: '输入的长度请在 50 个字符',
      trigger: 'blur'
    }
  ],
  price: [{
      required: true,
      message: '请输入购买价格',
      trigger: 'blur'
    },
    // {
    //   max: 50,
    //   message: '输入的长度请在 50 个字符',
    //   trigger: 'blur'
    // }
  ],
  equipment_site: [{
      required: true,
      message: '请输入设备地址',
      trigger: 'blur'
    },
    {
      max: 50,
      message: '输入的长度请在 50 个字符',
      trigger: 'blur'
    }
  ],
  port: [{
      required: true,
      message: '请输入通讯端口',
      trigger: 'blur'
    },
    // {
    //   max: 50,
    //   message: '输入的长度请在 50 个字符',
    //   trigger: 'blur'
    // }
  ],
  /* number */
  maintain_cycle: [{
      required: true,
      message: '请输入保养周期'
    },
    {
      type: 'number',
      message: '保养周期必须为数字值'
    }
  ],
  correct_cycle: [{
      required: true,
      message: '请输入效准周期'
    },
    {
      type: 'number',
      message: '效准周期必须为数字值'
    }
  ],
  maintain_waring: [{
      required: true,
      message: '请输入维保预警'
    },
    {
      type: 'number',
      message: '维保预警必须为数字值'
    }
  ],
  /* data */
  purchasing_date: [{
    type: 'date',
    required: true,
    message: '请输入购买日期',
    trigger: 'change'
  }, ],
  /* select */
  equipment_type_id: [{
    required: true,
    message: '请选择设备类别',
    trigger: 'change'
  }, ],
  location: [{
    required: true,
    message: '请选择存放位置',
    trigger: 'change'
  }],
  locations: [{
    required: true,
    message: '请选择存放位置',
    trigger: 'change'
  }],
  options: [{
    required: true,
    message: '请选择借用设置',
    trigger: 'change'
  }],
  /*单选*/
  is_maintain: [{
      required: true,
      message: '请选择是否维护',
      trigger: 'change'
    },
    {
      type: 'number',
      min: 0,
      message: '请选择是否维护',
      trigger: 'change'
    }
  ],
  is_monitor: [{
      required: true,
      message: '请选择是否监控',
      trigger: 'change'
    },
    {
      type: 'number',
      min: 0,
      message: '请选择是否监控',
      trigger: 'change'
    }
  ],
  is_transmission: [{
      required: true,
      message: '请选择数据传输',
      trigger: 'change'
    },
    {
      type: 'number',
      min: 0,
      message: '请选择数据传输',
      trigger: 'change'
    }
  ],
  mode: [{
      required: true,
      message: '请选择传输方式',
      trigger: 'change'
    },
    {
      type: 'number',
      min: 0,
      message: '请选择传输方式',
      trigger: 'change'
    }
  ],
  pictureUrl: [{
    required: true,
    message: '请上传图片',
  }],
  voltage_waring: [
    {
      required: true,
      message: '请输入电压预警',
      trigger: 'change'
    }
  ],
  electricity_waring: [
    {
      required: true,
      message: '请输入电流预警',
      trigger: 'change'
    }
  ],
  // phoneNum: [{
  //   required: true,
  //   validator: checkPhone,
  //   trigger: "blur"
  // }],
  interface_type: [{
      required: true,
      message: '请选择接口类型',
      trigger: 'change'
    },
    {
      type: 'number',
      min: 0,
      message: '请选择接口类型',
      trigger: 'change'
    }
  ],
  is_run: [{
      required: true,
      message: '请选择是否启用',
      trigger: 'change'
    },
    {
      type: 'number',
      min: 0,
      message: '请选择是否启用',
      trigger: 'change'
    }
  ],
  /*/!* 图片 *!/
  picture_url: [{
      required: true, message: '请上传图片', trigger: 'change' }
  ],*/
}
export function jsonToArray(nodes) {
  var r=[];
  if (Array.isArray(nodes)) {
    for (var i=0, l=nodes.length; i<l; i++) {
      r.push(nodes[i]); // 取每项数据放入一个新数组
      if (Array.isArray(nodes[i]["children"])&&nodes[i]["children"].length>0)
       // 若存在children则递归调用，把数据拼接到新数组中，并且删除该children
        r = r.concat(jsonToArray(nodes[i]["children"]));
          delete nodes[i]["children"]
    }
  } 
  return r;
}
export const serverArr = (data, value) => {
  let retrunData = []
  for (let i = 0; i < data.length; i++)
    data.forEach(item => {
      if (item.value == value) {
        retrunData = [item.value];
      } else {
        if (item.children) {
          let msg = serverArr (item.children, value)
          if (msg && msg.length != 0) {
            msg.unshift(item.value)
            retrunData = msg;
          }
        }
      }
    })
  return retrunData;
}